package cn.xiaolang.thread.threadlocal;

/**
 *
 * @author Dean
 * @date 2021-01-23
 */
public class ThreadLocalStarted {

	private static final ThreadLocal<Integer> TL_INT = ThreadLocal.withInitial(() -> 6);

	public static void main(String... args) {
		initValueSample();
	}

	private static void initValueSample() {
		// 6
		System.out.println("初始化的值: " + TL_INT.get());
		TL_INT.set(TL_INT.get() + 1);
		// 7 == Thread.currentThread().threadLocals.getEntry(TL_INT).value
		System.out.println("数值变更: " + TL_INT.get());
		TL_INT.remove();
		// 会重新初始化该value，6
		System.out.println("调用remove后的值恢复初始化: " + TL_INT.get());
	}

}
